<!DOCTYPE html>
<title>Verify that we don't crash on close if the MediaSource.sourceBuffers holds the last reference to its SourceBuffer objects.</title>
<script src="/w3c/resources/testharness.js"></script>
<script src="/w3c/resources/testharnessreport.js"></script>
<video></video>
<script>
async_test(function(t) {
    var video = document.createElement("video");
    var mediaSource = new MediaSource();

    mediaSource.addEventListener('sourceopen', function() {
        mediaSource.addSourceBuffer('video/webm;codecs="vp8"');

        // Running garbage collector to cleanup the SourceBuffer reference returned by addSourceBuffer().
        gc();

        video.src = "";
    });

    mediaSource.onsourceclose = t.step_func_done();
    video.src = URL.createObjectURL(mediaSource);
});
</script>